package com.zzyl.serve.controller;

import com.zzyl.serve.dto.CancelDto;
import com.zzyl.serve.dto.DoDto;
import com.zzyl.serve.dto.UpdateTimeDto;
import com.zzyl.serve.vo.NursingTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.serve.domain.NursingTask;
import com.zzyl.serve.dto.NursingTaskDto;
import com.zzyl.serve.service.INursingTaskService;
import com.zzyl.serve.vo.NursingTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "护理任务管理")
@Slf4j
public class NursingTaskController extends BaseController {
    @Autowired
    private INursingTaskService nursingTaskService;

    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    @SuppressWarnings("unchecked")
    public TableDataInfo<List<NursingTask>> list(NursingTaskDto dto) {
        startPage();
        return getDataTable(nursingTaskService.selectNursingTaskList(dto));
    }


    /**
     * 获取护理任务详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取护理任务详细信息")
    public R<NursingTaskVo> getInfo(@ApiParam(value = "护理任务ID", required = true) @PathVariable("id") Long id) {
        return R.ok(nursingTaskService.selectNursingTaskById(id));
    }

    @PutMapping(value = "/cancel")
    @ApiOperation("取消护理任务")
    public AjaxResult cancel(@RequestBody CancelDto dto) {
        NursingTask nursingTask = nursingTaskService.selectNursingTaskById(dto.getTaskId());
        nursingTask.setStatus(3);
        nursingTask.setCancelReason(dto.getReason());
        nursingTaskService.updateById(nursingTask);
        return success();
                             }
   @PutMapping(value = "/do")
@ApiOperation("执行护理任务")
public AjaxResult doTask(@RequestBody DoDto dto) {
    NursingTask nursingTask = nursingTaskService.selectNursingTaskById(dto.getTaskId());
    nursingTask.setEstimatedServerTime(dto.getEstimatedServerTime());
    nursingTask.setMark(dto.getMark());
    nursingTask.setTaskImage(dto.getTaskImages());
       nursingTask.setStatus(2);

    nursingTaskService.updateById(nursingTask);
    return success();
}
  @PutMapping (value ="/updateTime")
    @ApiOperation("更新护理任务时间")
    public AjaxResult updateTime(@RequestBody UpdateTimeDto dto) {
      NursingTask nursingTask = nursingTaskService.selectNursingTaskById(dto.getTaskId());
        nursingTask.setEstimatedServerTime(dto.getEstimatedDateTime());

        nursingTaskService.updateById(nursingTask);
        return success();
    }


}


